package com.mianshi;

import com.example.myproject.domain.User;

/**
 * Created by xi on 2018/12/1.
 */
public class ThreadLocalTest {
    //
    static ThreadLocal a = new ThreadLocal();
    public static void main(String[] args) {
        new Thread(new Runnable() {
            @Override public void run() {
                User user = new User();
                user.setName("zhangan");
                a.set(user);
                System.out.println("ag" + a.get());
                User other = (User) a.get();
                other.setName("55555");
                System.out.print("result:"+(((User) a.get()).getName()));

            }
        }).start();
        new Thread(new Runnable() {
            @Override public void run() {
                User user = new User();
                user.setName("zhangan");
                a.set(user);
                System.out.print("sd" + a.get());
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.print("result:"+(((User) a.get()).getName()));
            }
        }).start();

    }
}
